package com.example.administrator.myokhttpmvp.net;

import android.os.Build;

import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.BitmapCallback;
import com.zhy.http.okhttp.callback.StringCallback;


/**
 * @Created HaiyuKing
 * @Used 登录界面相关接口
 */
public class UserNet  {

    private static UserNet instance = null;

    public static synchronized UserNet Instance() {
        if (instance == null)
            instance = new UserNet();
        return instance;
    }


    /**
     * 获取手机验证码
     */
    public void mobileCode(String phone, StringCallback callback)
            throws Exception {
        OkHttpUtils
                .get()
                .url(ServerApi.URL_mobileCode+ "?mobile=" + phone )
                .id(100)
                .tag(MyApplication.getAppContext())
                .build()
                .execute(callback);
    }
    /**
     * 获取手机验证码
     */
    public void app_login(String phone, String mobileCode, StringCallback callback)
            throws Exception {
        OkHttpUtils
                .get()
                .url(ServerApi.URL_app_login+  "?mobile=" + phone + "&mobileCode=" + mobileCode)
                .id(100)
                .tag(MyApplication.getAppContext())
                .build()
                .execute(callback);
    }

    /**
     * 获取手机验证码
     */
    public void mobile_info(StringCallback callback)
            throws Exception {
        OkHttpUtils
                .post()
//                .addHeader("token", PrefManager.getInstance().get().getString(ServerApi.SP_TOKEN,""))
                .url(ServerApi.URL_mobile_info)
                .id(100)
                .tag(MyApplication.getAppContext())
                .addParams("mobileInfo", Build.ID)
                .build()
                .execute(callback);
    }
}



/*
//https://www.cnblogs.com/whycxb/p/7636249.html
//Post请求
public String LoginApi(String userName, String password,StringCallback callback)
            throws Exception {
        String result = "";
        OkHttpUtils
                .post()
                .url(getSpcyUrl(ServerApi.LOGIN_URL))
                .addParams("user.userName", userName)
                .addParams("user.password", password)
                .addParams("IS_JSON", "true")
                .addParams("loginModel", "mobile")
                .addParams("VALUE_OBJES_4_JSON", "loginUser")
                .addParams("userLoginModel", "mobile")
                .id(100)
                .tag(context)
                .build()
                .execute(callback);
         return result;
    }


//postString【Json数据】请求
public String postJsonApi(PostJsonModel postJsonModel, StringCallback callback){
        String result = "";
        OkHttpUtils
                .postString()
                .url(getSpcyUrl(ServerApi.POSTJSON_URL))
                .content(new Gson().toJson(postJsonModel))
                .mediaType(MediaType.parse("application/json; charset=utf-8"))
                .id(100)
                .tag(context)
                .build()
                .execute(callback);
        return result;
    }

//post提交文件请求
public String postFileApi(File file, StringCallback callback){
        String result = "";
        OkHttpUtils
                .postFile()
                .url(getSpcyUrl(ServerApi.POSTFILE_URL))
                .file(file)
                .id(100)
                .tag(context)
                .build()
                .execute(callback);
        return result;
    }

*/